﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;

namespace ryan
{
    class Menu
    {
        private const float WAIT_PRESENT = 0f;

        private Rectangle backgroundBase, title;
        private Texture2D spriteBackgroundBase, spriteTitle;
        private Text presentText, newGameText, optionText;
        private SpriteFont fontImpact;
        private float waitPresent;
        private int vitesse;
        private bool statut;

        public Menu()
        {
            this.backgroundBase = new Rectangle(0, 0, (int)(1920 / 2.4), (int)(1080 / 2.25));
            this.presentText = new Text("PRESENTE", Color.Black, Color.White, 1, 2, 0, new Vector2(405, 250));

            this.newGameText = new Text("Nouvelle Partie", Color.Black, Color.Black, 1, 2, 0, new Vector2(390, 270));
            this.newGameText.ColorBack.A = 0;
            this.newGameText.ColorFront.A = 0;

            this.optionText = new Text("Option", Color.Black, Color.Black, 1, 2, 0, new Vector2(390, 320));
            this.optionText.ColorBack.A = 0;
            this.optionText.ColorFront.A = 0;

            this.waitPresent = WAIT_PRESENT;
            this.vitesse = 5;
            this.title = new Rectangle(250, 500, (int)(414 / 1.5), (int)(271 / 1.5));
            this.statut = true;
        }

        public void LoadContent(ContentManager theContentManager)
        {
            this.spriteBackgroundBase = theContentManager.Load<Texture2D>("BootScreen/BootScreen2");
            this.fontImpact = theContentManager.Load<SpriteFont>("SpriteFont_Impact");
            this.spriteTitle = theContentManager.Load<Texture2D>("title");
        }

        public bool GetStatut()
        {
            return this.statut;
        }

        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePad, GameTime gameTime)
        {
            if (keyboard.IsKeyDown(Keys.Enter))
            {
                this.statut = false;
            }

            if (this.title.Y < 50)
            {
                if (this.newGameText.ColorBack.A < 255)
                {
                    this.newGameText.ColorBack.A += 1;
                    this.newGameText.ColorFront.A += 1;
                    this.newGameText.ColorFront.R += 1;
                    this.newGameText.ColorFront.G += 1;
                    this.newGameText.ColorFront.B += 1;

                    this.optionText.ColorBack.A += 1;
                    this.optionText.ColorFront.A += 1;
                    this.optionText.ColorFront.R += 1;
                    this.optionText.ColorFront.G += 1;
                    this.optionText.ColorFront.B += 1;
                }
                else
                {
                    this.newGameText.ColorBack.A = 255;
                    this.newGameText.ColorFront.A = 255;
                    this.newGameText.ColorFront.R = 255;
                    this.newGameText.ColorFront.G = 255;
                    this.newGameText.ColorFront.B = 255;
                }
            }
            else if (this.waitPresent > 2000f)
            {
                this.presentText.Position.Y -= this.vitesse;
                this.title.Y -= this.vitesse;
            }
            else
            {
                this.waitPresent += gameTime.ElapsedGameTime.Milliseconds;
            }
        }

        public void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(this.spriteBackgroundBase, this.backgroundBase, Color.White);
            
            if (this.presentText.Position.Y > -100)
            {
                this.presentText.Draw(theSpriteBatch, this.fontImpact);
            }

            theSpriteBatch.Draw(this.spriteTitle, this.title, Color.White);
            this.newGameText.Draw(theSpriteBatch, this.fontImpact);
            this.optionText.Draw(theSpriteBatch, this.fontImpact);
        }

    }
}
